﻿using UnityEngine;
using System.Collections;

public class BatFlyingController : BaseController
{
	// Properties

	[SerializeField]
	float				m_xrange	= 20f;
	[SerializeField]
	float				m_yrange	= 8f;
	[SerializeField]
	float				m_randomness	= 1f;
	[SerializeField]
	float				m_cycleTime	= 2f;



	// Members

	float				m_startTime;
	Vector3				m_startPos;

	bool				m_posInit;

	protected override void OnInitialize ()
	{
		base.OnInitialize ();

		m_startTime		= Time.time;
	}


	protected override void OnUpdate ()
	{
		base.OnUpdate ();

		if(m_posInit == false)			// * 시작 위치 구하기
		{
			m_posInit	= true;
			m_startPos	= transform.localPosition;
		}

		Vector2 newPos	= new Vector2();
		float elapsed	= Time.time - m_startTime;

		float sinValue	= Mathf.Sin(2 * Mathf.PI * (elapsed / m_cycleTime));
		float sinValue2	= Mathf.Sin(4 * Mathf.PI * (elapsed / m_cycleTime));
		newPos.x		= sinValue * m_xrange;
		newPos.y		= sinValue2 * m_yrange;

		newPos			+= Random.insideUnitCircle * m_randomness;

		transform.localPosition	= m_startPos + new Vector3(newPos.x, newPos.y);
	}
}
